package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.course.CourseVideo;
import com.hualan.sfzy.service.course.CourseVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseVideoController {
    @Autowired
    private CourseVideoService courseVideoService;
    @PostMapping("/courseVideo")
    public String add(@RequestBody CourseVideo courseVideo) {
        return courseVideoService.add(courseVideo) >0?"success":"fail";
    }
    @PutMapping("/courseVideo")
    public String edit(@RequestBody CourseVideo courseVideo) {
        return courseVideoService.edit(courseVideo)>0?"success":"fail";
    }
    @DeleteMapping("/courseVideo")
    public String remove(Integer[] ids) {
        return courseVideoService.removeBatch(ids) > 0?"success":"fail";
    }
    @DeleteMapping("/courseVideo/{id}")
    public String remove(@PathVariable Integer id) {
        return courseVideoService.remove(id)>0?"success":"fail";
    }
    @GetMapping("/courseVideo")
    public List<CourseVideo> find() {
        return courseVideoService.find();
    }
    @GetMapping("/courseVideo/{id}")
    public CourseVideo findById(@PathVariable Integer id) {
        return courseVideoService.findById(id);
    }
    @GetMapping("/courseVideo/page")
    public Object findPage(
            @RequestParam(value = "pageNum",defaultValue = "1",required = false)
            Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5",required = false)
            Integer pageSize
            ,CourseVideo courseVideo) {
        return courseVideoService.findPage(pageNum, pageSize, courseVideo);
    }
}